const express=require('express');
//引入连接池
const query=require('../util/query.js');
//创建空路由器s
let router=express.Router();

//获取首页轮播图列表
router.get('/carousel',async(req,res)=>{
    let sql = "select id,img from v_carousel ";
    try {
        let result = await query(sql);
        let data=result;

        if (result.length > 0) {
            //图片路径位置从根开始的
            res.send({ code: 1, msg: "加载轮播图成功" ,data});           
        }
        else{
          throw "Query返回记录数不大于0";
        }
    } catch (error) {
        res.send({ code: 0, msg: `加载轮播图失败, error: ${error}` }); //throw err;  
    }
});



module.exports=router;